#include "stdafx.h"
#include "lookup.h"
#include "writer.h"
#include "debug.h"


void lyric_lookup_task::run(threaded_process_status & p_status, abort_callback & p_abort)
{
	pfc::string_list_impl list;

	p_status.set_progress_float(0.0);

	// Querying
	if (m_provider.is_valid())
	{
		m_provider->query(m_data, list, p_status, p_abort);
	}
	else
	{
		popup_message_error("No lyrics provider found.");
	}

	if (p_abort.is_aborting())
		return;

	// Add updating task to a main thread, which create modeless dialog there
	static_api_ptr_t<main_thread_callback_manager> mtcm;
	mtcm->add_callback(new service_impl_t<main_thread_callback_tag_writer>(m_data, list));
}

void lyric_lookup_task::start()
{
	threaded_process::g_run_modeless(
		this,
		threaded_process::flag_show_abort |
		threaded_process::flag_show_minimize |
		threaded_process::flag_show_progress |
		threaded_process::flag_show_item |
		threaded_process::flag_show_delayed |
		threaded_process::flag_no_focus,
		core_api::get_main_window(),
		"Querying lyrics..."
		);
}
